#!/usr/bin/env python
# -*- coding:utf-8 -*-


# Created by zhenqin.
# User: zhenqin
# Date: 16/8/16
# Time: 13:46
# Verdor: NowledgeData
# To change this template use File | Settings | File Templates.
#

from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.protocol import TCompactProtocol
import ThriftHelloWorldProtocol
from ttypes import User
from ttypes import Message
from datetime import datetime
import time

__author__ = "zhenqin"


def thriftClientExe():
    try:
        sock = TSocket.TSocket('localhost', 8088)
        transport = TTransport.TBufferedTransport(sock)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        client = ThriftHelloWorldProtocol.Client(protocol)
        transport.open()

        user = User()
        user.name = 'Thrift Python'

        for i in range(0, 100, 10):
            print(client.sayHello(user))

        transport.close()
    except Thrift.TException, tx:
        print format(tx.message)


if __name__ == "__main__":
    thriftClientExe()
    pass
